const deliverInfoFacade = require('../../app/facade/deliverInfo.facade.js');
const _ = require('lodash');

module.exports = {
    addDeliverInfoByClient:addDeliverInfoByClient,
    getDeliverInfoByClient:getDeliverInfoByClient,
    updateDeliverInfo:updateDeliverInfo,
    deleteDeliverInfoById:deleteDeliverInfoById
}

function addDeliverInfoByClient(req, res, next) {
    let deliverInfo = req.body;
    deliverInfoFacade.addDeliverInfoByClient(deliverInfo, (error, result)=>{
        if(error) {
            return next(new Error(error));
        }else {
            return res.json(result);
        }
    })
}

function getDeliverInfoByClient(req, res, next) {
    let cid = req.params.cid;
    deliverInfoFacade.getDeliverInfoByClient(cid, (error, result) => {
        if(error) {
            return next(new Error(error));
        } else{
            return res.json(result);
        }
    })
}

function updateDeliverInfo(req, res, next) {
    let dinfo = req.body;
    deliverInfoFacade.updateDeliverInfo(dinfo, (error, result)=>{
        if(error) {
            return next(new Error(error));
        }else {
            return res.json(result);
        }
    })
}

function deleteDeliverInfoById(req, res, next) {
    let did = req.params.id;
    deliverInfoFacade.deleteDeliverInfoById(did, (error, result) => {
        if(error) {
            return next(new Error(error));
        } else{
            return res.json(result);
        }
    })
}
